import {
	timeDifference
} from '@/utils/filterTime.js';
export default {
	data() {
		return {
			dateShow: false,
			weekArrayList: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
			difference: ['今天', '明天', '后天'],
		};
	},
	computed: {
		weekShow() {
			//展示的时间
			const dateInfo = {
				startDay: '',
				endDay: '',
				startWeek: '',
				endWeek: '',
				totalDay: ''
			};
			//已选择的时间
			const {
				startDate,
				endDate
			} = this.params;
			//默认当前时间
			const defaultDate = this.$filterTime({
				isHours: false
			});
			//格式化时间
			const start = new Date(startDate);
			const end = new Date(endDate);
			//开始时间距离今天差的天数
			const startDifference = timeDifference(new Date(defaultDate), start)['days'];
			//结束时间距离今天差的天数
			const endDifference = timeDifference(new Date(defaultDate), end)['days'];
			// 转化为今明后或者星期几
			dateInfo.startWeek = this.difference[startDifference] || this.weekArrayList[start.getDay()];
			dateInfo.endWeek = this.difference[endDifference] || this.weekArrayList[end.getDay()];
			//转化为月日
			dateInfo.startDay = this.disposeDate(start);
			dateInfo.endDay = this.disposeDate(end);
			//住了几天
			dateInfo.totalDay = (end - start) / (1 * 24 * 60 * 60 * 1000);
			return dateInfo;
		}
	},
	methods: {
		disposeDate(date) {
			let dateArr = this.$filterTime({
				date,
				isHours: false
			}).split('-');
			dateArr.splice(0, 1);
			dateArr = dateArr.join('月') + '日';
			return dateArr;
		},
		confirmDate(date) {
			this.params.startDate = date[0];
			this.params.endDate = date[date.length - 1];
			this.dateShow = false;
			console.log(date);
		}
	}
};